#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json

def main():
    output_file_name = '/home/ivy/git/Social/Social/resource/user_degree.txt'
    
    current_user = ''
    with open(output_file_name, "a+") as outputfile:
        for i in range(1, 15):
            input_file_name = '/home/ivy/git/Social/Social/resource/json_tweets_%d.txt' % i
        
            with open(input_file_name, "r") as inputfile:
                for line in inputfile:
                    obj = json.loads(line)
                    user = obj['users']
                    if user == current_user:
                        continue
                    
                    current_user = user
                    in_degree = obj['followers']
                    out_degree = obj['friends']
                    outputfile.write('%s\t%d\t%d\n' % (user, in_degree, out_degree))
            
            outputfile.flush()
    
    outputfile.close()
    
if __name__ == '__main__':
    main() 